package com.qianfeng.controller;

import com.qianfeng.dto.Page;
import com.qianfeng.entity.Department;
import com.qianfeng.entity.Doctor;
import com.qianfeng.service.DepartmentService;
import com.qianfeng.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.ws.rs.PUT;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
public class DoctorController {
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private DepartmentService departmentService;

    @RequestMapping("/getDoctorList")
    public String getDoctorList(){
        return "09_outpatient_management";
    }
    @ResponseBody
    @RequestMapping("/getDoctorPage")
    public Page getDoctorPage(Integer pageNo,Integer pageSize){
        int pageNo_=1;
        int pageSize_=2;
        if (pageNo!=null){
            pageNo_=pageNo;
        }
        if (pageSize!=null){
            pageSize_=pageSize;
        }
        Page page = doctorService.getDoctorPage(pageNo_, pageSize_);
        return page;
    }
    @RequestMapping("/jumpAddDoctor")
    public String jumpAddDoctor(Map map){
        List<Department> departmentList = departmentService.getDepartmentList();
        map.put("departments",departmentList);
        return "09_01_outpatient_management_add";
    }

    @RequestMapping("/addDoctor")
    public String addDoctor(Doctor doctor){
        doctor.setdHiredate(new Date());
        doctor.setdState(1);
        doctorService.addDoctor(doctor);
        return "09_outpatient_management";
    }
    @RequestMapping("/getDoctorDetail")
    public String getDoctorDetail(Integer dId,Map map){
        Doctor doctor = doctorService.getDoctorById(dId);
        map.put("doctor",doctor);
        List<Department> departmentList = departmentService.getDepartmentList();
        map.put("department",departmentList);
        return "09_03_outpatient_management_detail";
    }

    @RequestMapping("/jumpUpdateDoctor")
    public String jumpUpdateDoctor(Integer dId,Map map){
        Doctor doctor = doctorService.getDoctorById(dId);
        map.put("doctor",doctor);
        List<Department>departmentList  = departmentService.getDepartmentList();
        map.put("department",departmentList);
        return "09_02_outpatient_management_update";
    }
    @RequestMapping("/updateDoctor")
    public String updateDoctor(Doctor doctor){
        doctorService.updateDoctor(doctor);
        return "09_outpatient_management";
    }

}
